package com.zgc.view.common;

import com.zgc.view.controller.NewConnectionCtrl;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ContextMenuCtrl {

    private ContextMenu contextMenu;
    @Autowired
    private AlertCtrl alertCtrl;
    @Autowired
    private NewConnectionCtrl connectionCtrl;

    public ContextMenu load() {
        if (contextMenu == null) {
            initialize();
        }
        return contextMenu;
    }

    private void initialize() {
        MenuItem newConnectMenu = new MenuItem("新建连接");
        MenuItem exportConnectMenu = new MenuItem("导出");
        MenuItem importConnectMenu = new MenuItem("导入");
        newConnectMenu.setOnAction(event -> connectionCtrl.showNewConnectionAlert());
        exportConnectMenu.setOnAction(event -> alertCtrl.setMessageAndShow("导出连接（待开发）"));
        importConnectMenu.setOnAction(event -> alertCtrl.setMessageAndShow("导入连接（待开发）"));
        contextMenu = new ContextMenu(newConnectMenu, exportConnectMenu, importConnectMenu);
    }

}
